#ifndef QTOOLGRAPHICSSCENE_H
#define QTOOLGRAPHICSSCENE_H

#include "tools_global.h"
#include <QGraphicsScene>
#include <QMap>
#include <QString>
#include "../Controller/centralController.h"
#include <QBrush>
#include <QPen>
#include <QColor>
#include <QFont>

class QMyTool;

class TOOLS_EXPORT QToolGraphicsScene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit QToolGraphicsScene(QObject *parent = 0);
    QToolGraphicsScene(const QRectF & sceneRect,QObject *parent=0);
    QToolGraphicsScene(qreal x,qreal y,qreal width,qreal height,QObject * parent =0);
    ~QToolGraphicsScene();
    bool AddTool(QString name,QMyTool * tool_pt);
    bool SetCurrentTool(QString name);
	QMyTool *GetCurrentTool(){return currentTool;}
	int CurrentTime(){return currentTime;}
	void SetTime(int time);
	void SetCurrentContainer(nodePath path);
	void SetController(centralController *ctrl){controller=ctrl;}
	void Enter(){++ContainerEnter;}
	void Leave(){--ContainerEnter;}
	bool isEntered(){return ContainerEnter!=0;}
	void AddItemLink(QGraphicsItem* item,int index){itemsMap[item]=index;}

	void RemoveItemLink(QGraphicsItem* item){itemsMap.remove(item);}
	int ItemIndex(QGraphicsItem* item){ return itemsMap.value(item);}
	bool IsItemExist(QGraphicsItem* item){return itemsMap.contains(item);}

	void SetPen(const QPen& pen){CurrentPen=pen;}
	void SetBrush(const QBrush& brush){CurrentBrush=brush;}
	const QPen& Pen(){return CurrentPen;}
	const QBrush& Brush(){return CurrentBrush;}
	void AddPixmapItem(int node_index);

protected:
    virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * contextMenuEvent);
    virtual void mouseMoveEvent (QGraphicsSceneMouseEvent * mouseEvent );
    virtual void mousePressEvent (QGraphicsSceneMouseEvent * mouseEvent);
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent );
    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * mouseEvent );
private:
    QMyTool *currentTool;
    QMap<QString,QMyTool* > ToolDict;
	int currentTime;
	centralController *controller;
    int ContainerEnter;
	QMap<QGraphicsItem*,int> itemsMap;

	QBrush CurrentBrush;
	QPen CurrentPen;
signals:
    
public slots:
    
};

#endif // QTOOLGRAPHICSSCENE_H
